<!--
 * @Author: yaojian66 1327629137@qq.com
 * @Date: 2022-07-05 16:40:36
 * @LastEditors: yaojian66 1327629137@qq.com
 * @LastEditTime: 2022-07-05 16:44:56
 * @FilePath: \geyao\第一百一十七题 指定包名.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>创建对象</title>
</head>

<body>
  <script>
    function namespace(oNamespace, sPackage) {
      const arr = sPackage.split('.');
      let o = oNamespace;
      for (let i = 0; i < arr.length; i++) {
        // 如果不是对象，则使它成为对象
        if (typeof o[arr[i]] != 'object') {
          o[arr[i]] = {};
        }
        o = o[arr[i]];
      }
      return oNamespace;
    }
    console.log(namespace({a: {test: 1, b: 2}}, 'a.b.c.d'),"haha")
    
  </script>
</body>

</html>